<?php
/**
 * Created by xuan.
 * Author: xuan
 * Date: 2018/8/3
 * Time: 18:24
 */

namespace app\api\model;
use think\Db;

class Admin extends BaseModel
{	
	protected $table = 'admin';
	
	public static function selectOneAdminByName($username){
		$data = model("Admin")->where(array("username"=>$username))->find();
		return $data;
	}
	
	public static function selectOneMemberByTel($tel){
		$data = model("Member")->where(array("tel"=>$tel))->find();
		return $data;
	}
	
	public static function selectOneMemberByIdnum($idnum){
		$data = model("Member")->where(array("idnum"=>$idnum))->find();
		return $data;
	}
	
	public static function selectOneMemberByID($id){
		$data = model("Member")->where(array("id"=>$id))->find();
		return $data;
	}
	
	public static function addOneAdmin($all)
    {
		$data = Admin::create([
			'username' => $all['username'],
			'password' => $all['password'],
			'addtime' => date('Y-m-d H:i:s',time()),
			'updatetime' => date('Y-m-d H:i:s',time())
		]);
		  
		return $data;
    }
	
	public static function MemberLists(){
		$data = model("Member")->select();
		return $data;
	}
	
	/**
     * @param $where
     * @return array|false|\PDOStatement|string|\think\Model
     * 查询详情
     */
    public static function getListByWhere($where, $page = 0, $pageSize = 10 ,$order = "id DESC"){
        $pageSize = $pageSize <= 0 ? 10 : $pageSize;
        $list = Db::name('Member')->where($where)->limit($page, $pageSize)->order($order)->select();
		return $list;
    }
	
	public static function getCount($where = ''){
        return Db::name('Member')->where($where)->count();
    } 
	
    public static function shenhe($all){
		$count = Db::name('Member')->where('id',$all['id'])->update(['status' => $all['status'],'beizhu' => $all['beizhu']]);
		return $count;
	}
    
}